package com.kuangjia.boss.commonSafety.aes;

import lombok.SneakyThrows;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component("JasyptUtils")
public class JasyptUtils implements StringEncryptor {

    @Value("${jasypt.encryptor.salt:28392D243E282731373A372734}")
    private String salt;

    /**
     * 加密
     * @param message
     * @return
     */
    @SneakyThrows
    @Override
    public String encrypt(String message) {
//        String encryptHex = CustomStringUtil.byte2hex(AesUtil.getEncryptedTokenByRandom(message,salt));
//        return encryptHex;
        return AESUtils.aesEncrypt(message,salt);
    }

    /**
     * 解密
     * @param encryptedMessage
     * @return
     */
    @SneakyThrows
    @Override
    public String decrypt(String encryptedMessage) {
//        System.out.println("加密STR======================"+encryptedMessage);
//        String decryptStr = new String(AesUtil.getDecryptedTokenByRandom(encryptedMessage,salt));
//        System.out.println("加密密码======================"+decryptStr);
//        return decryptStr;内存一下
        final String aesDecrypt = AESUtils.aesDecrypt(encryptedMessage, salt);
//        System.out.println("解密STR======================"+aesDecrypt);
        return  aesDecrypt;
    }

}
